package com.dc.service;

import com.dc.constant.Constants;
import com.dc.dao.*;
import com.dc.dao.vo.stat.CalibrationShipCutStatVO;
import com.dc.entity.*;
import com.dc.service.dto.*;
import com.github.pagehelper.Constant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.xmlbeans.impl.xb.xsdschema.impl.DocumentationDocumentImpl;
import org.aspectj.weaver.ast.Var;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.DuplicateFormatFlagsException;
import java.util.List;

/**
 * 标定工序计算服务
 */
@Service
@Slf4j
public class CalibrationService {

    @Resource
    private CalibrationAirPowerDao airPowerDao;

    @Resource
    private CalibrationShipCutDao calibrationShipCutDao;

    @Resource
    private CalibrationShipOldDao calibrationShipOldDao;

    @Resource
    private CalibrationShipWeldDao calibrationShipWeldDao;

    @Resource
    private CalibrationMachinePipeDao calibrationMachinePipeDao;

    @Resource
    private CalibrationPaintShipDao calibrationPaintShipDao;

    @Resource
    private CalibrationPaintHouseDao calibrationPaintHouseDao;

    @Resource
    private CalibrationHouseSandDao calibrationHouseSandDao;

    @Resource
    private CalibrationShipSandDao calibrationShipSandDao;

    @Resource
    private CalibrationWaterCleanPointDao calibrationWaterCleanPointDao;

    @Resource
    private CalibrationWaterCleanDao calibrationWaterCleanDao;

    @Resource
    private CalibrationWaterRustCleanDao calibrationWaterRustCleanDao;

    @Resource
    private CalibrationWaterCleanRustShipDao calibrationWaterCleanRustShipDao;

    /**
     * 动态计算
     * @param entity
     * @return
     */
    public CalibrationShipOldEntity calc(CalibrationShipOldEntity entity) {
        try {
            //gas = endGas - startGas
            entity.gas = entity.endGas - entity.startGas;
        } catch (Exception e) {
            entity.gas = 0.;
        }

        try {
            //gasByUnit = gas/length
            entity.gasByUnit = entity.gas / entity.length;
        } catch (Exception e) {
            entity.gasByUnit = 0.;
        }

        try {
            //o2 = endO2 - startO2
            entity.o2 = entity.endO2 - entity.startO2;
        } catch (Exception e) {
            entity.o2 = 0.;
        }

        try {
            //o2ByUnit = o2/length
            entity.o2ByUnit = entity.o2 / entity.length;
        } catch (Exception e) {
            entity.o2ByUnit = 0.;
        }

        return entity;
    }

    /**
     * 动态计算船体下料
     * @param entity
     * @return
     */
    public CalibrationShipCutEntity calc(CalibrationShipCutEntity entity) {
        // area
        try {
            entity.area = entity.width * entity.length * 0.000001;
        } catch (Exception e) {
            entity.area = 0.;
        }

        //weight = length * width * thickness * num * 7.85/1000000
        try {
            entity.weight = entity.length * entity.width * entity.thickness * entity.num * 7.85 / 1000000;
        } catch (Exception e) {
            entity.weight = 0.;
        }

        try {
            //power = (endPower - startPower) * 50
            entity.power = (entity.endPower - entity.startPower) * 50;
        } catch (Exception e) {
            entity.power = 0.;
        }

        try {
            //powerByUnit = power / (cutLength * thickness/1000)
            entity.powerByUnit = entity.power / (entity.cutLength * entity.thickness / 1000);
        } catch (Exception e) {
            entity.powerByUnit = 0.;
        }

        try {
            //o2 = endO2 - startO2
            entity.o2 = entity.endO2 - entity.startO2;
        } catch (Exception e) {
            entity.o2 = 0.;
        }

        try {
            //o2ByUnit = o2 / (cutLength * thickness / 1000)
            entity.o2ByUnit = entity.o2 / (entity.cutLength * entity.thickness / 1000);
        } catch (Exception e) {
            entity.o2ByUnit = 0.;
        }

        try {
            //air = endAir - startAir
            entity.air = entity.endAir - entity.startAir;
        } catch (Exception e) {
            entity.air = 0.;
        }

        try {
            //airByUnit = air / (cutLength * thickness / 1000)
            entity.airByUnit = entity.air / (entity.cutLength * entity.thickness / 1000);
        } catch (Exception e) {
            entity.airByUnit = 0.;
        }

        return entity;
    }

    /**
     * 单位压缩空气量耗电量标定值（KWH/m³)   三级
     */
    public Double calcUnitAirPower() {

        List<CalibrationAirPowerEntity> list = airPowerDao.findAll();

        double d = 0.;
        try {
            d = list.stream().mapToDouble(CalibrationAirPowerEntity::getPowerByUnit).average().orElse(0.0);
        } catch (Exception e) {
            d = 0.;
        }

        return d;
    }

    /**
     * 船体下料
     * @return
     */
    public CalibrationShipCutDto calcShipCut() {

        List<Double> powerByUnitList = new ArrayList<>(); // 单位耗电量

        List<Double> o2ByUnitList = new ArrayList<>();

        List<Double> airByUnitList = new ArrayList<>();

        List<CalibrationShipCutEntity> all = calibrationShipCutDao.findAll();

        all.forEach(t-> {
            powerByUnitList.add(t.getPowerByUnit());
            o2ByUnitList.add(t.getO2ByUnit());
            airByUnitList.add(t.getAirByUnit());
        });

        double powerByUnit = 0.;
        try {
            powerByUnit = powerByUnitList.stream().filter(ObjectUtils::isNotEmpty).mapToDouble(Double::doubleValue).average().orElse(0.0);   // 单位能耗
        } catch (Exception e) {
            powerByUnit = 0.0;
        }

        double o2ByUnit = 0.;
        try {
            o2ByUnit = o2ByUnitList.stream().filter(ObjectUtils::isNotEmpty).mapToDouble(Double::doubleValue).average().orElse(0.0);         // 单位耗氧
        } catch (Exception e) {
            o2ByUnit = 0.0;
        }

        double airByUnit = 0.;
        try {
            airByUnit = airByUnitList.stream().filter(ObjectUtils::isNotEmpty).mapToDouble(Double::doubleValue).average().orElse(0.0);       // 单位耗气
        } catch (Exception e) {
            airByUnit = 0.0;
        }

        double unitAirPower = calcUnitAirPower();

        double powerAirByUnit = 0.;
         try {
             powerAirByUnit = unitAirPower * airByUnit;                                                       // 单位耗电能标定值
         } catch (Exception e) {
             powerAirByUnit = 0.0;
         }

        CalibrationShipCutDto dto = new CalibrationShipCutDto(unitAirPower,powerByUnit, o2ByUnit, airByUnit, powerAirByUnit);

        return dto;
    }

    /**
     * 船体割旧
     * @return
     */
    public CalibrationShipOldDto calcShipOld() {

        List<Double> gasByUnitList = new ArrayList<>();

        List<Double> o2ByUnitList = new ArrayList<>();

        List<CalibrationShipOldEntity> all = calibrationShipOldDao.findAll();

        all.forEach(t-> {
            gasByUnitList.add(t.getGasByUnit());
            o2ByUnitList.add(t.getO2ByUnit());
        });

        double gasByUnit = 0.;
        try {
            gasByUnit = gasByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);       // 单位耗天然气量标定值
        } catch (Exception e) {
            gasByUnit = 0.;
        }

        double o2ByUnit = 0.;
         try {
             o2ByUnit = o2ByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);         // 单位耗氧气量标定值
         } catch (Exception e) {
             o2ByUnit = 0.;
         }

        CalibrationShipOldDto dto = new CalibrationShipOldDto(gasByUnit, o2ByUnit);

        return dto;
    }

    /**
     * 船体焊接
     */
    public CalibrationShipWeldDto calcShipWeld() {

        List<Double> powerByUnitList = new ArrayList<>();

        List<Double> co2ByUnitList = new ArrayList<>();

        List<CalibrationShipWeldEntity> all = calibrationShipWeldDao.findAll();

        all.forEach(t-> {
            powerByUnitList.add(t.getPowerByUnit());
            co2ByUnitList.add(t.getCo2ByUnit());
        });

        double powerByUnit = 0.;
        try {
            powerByUnit = powerByUnitList.stream().filter(ObjectUtils::isNotEmpty).mapToDouble(Double::doubleValue).average().orElse(0.0);       // 单位耗电量标定值
        } catch (Exception e) {
            powerByUnit = 0.0;
        }

        double co2ByUnit = 0.;
        try {
            co2ByUnit = co2ByUnitList.stream().filter(ObjectUtils::isNotEmpty).mapToDouble(Double::doubleValue).average().orElse(0.0);           // 单位耗CO2量标定值
        } catch (Exception e) {
            co2ByUnit = 0.;
        }

        CalibrationShipWeldDto dto = new CalibrationShipWeldDto(powerByUnit, co2ByUnit);

        return dto;
    }

    /**
     * 机电管子焊接
     * @return
     */
    public CalibrationMachinePipeDto calcMachinePipe() {

        List<Double> falanCo2PowerByUnitList = new ArrayList<>();

        List<Double> falanYahuPowerByUnitList = new ArrayList<>();

        List<Double> wantouYahuPowerByUnitList = new ArrayList<>();

        List<CalibrationMachinePipeEntity> all = calibrationMachinePipeDao.findAll();

        all.forEach(t-> {
            String type = t.getType();  // 弯头 法兰
            String method = t.getMethod();  // 氩弧 CO2
            if(Constants.TYPE_MACHINE_PIPE_FALAN.equals(type) && Constants.METHOD_MACHINE_PIPE_CO2.equals(method)) {
                falanCo2PowerByUnitList.add(t.getPowerByUnit());
            } else if(Constants.TYPE_MACHINE_PIPE_FALAN.equals(type) && Constants.METHOD_MACHINE_PIPE_YAHU.equals(method)) {
                falanYahuPowerByUnitList.add(t.getPowerByUnit());
            } else if(Constants.TYPE_MACHINE_PIPE_WANTOU.equals(type) && Constants.METHOD_MACHINE_PIPE_YAHU.equals(method)) {
                wantouYahuPowerByUnitList.add(t.getPowerByUnit());
            } else {
                log.warn("出现了未定义的标定计算，type = {}, method = {}", type, method);
            }

        });

        double falanCo2PowerByUnit = 0.;
        try {
            falanCo2PowerByUnit = falanCo2PowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);       // 法兰CO2焊接单位用电量标定值
        } catch (Exception e) {
            falanCo2PowerByUnit = 0.;
        }

        double falanYahuPowerByUnit = 0.;
        try {
            falanYahuPowerByUnit = falanYahuPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);     // 法兰氩弧焊接单位用电量标定值
        } catch (Exception e) {
            falanYahuPowerByUnit = 0.;
        }

        double falanPowerByUnit = 0.;
        try {
            falanPowerByUnit = falanYahuPowerByUnit + falanCo2PowerByUnit;                                                             // 法兰管子焊接单位用电量标定值
        } catch (Exception e) {
            falanPowerByUnit = 0.;
        }

        double wantouYahuPowerByUnit = 0.;
        try {
            wantouYahuPowerByUnit = wantouYahuPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);   // 弯头管子焊接单位用电量标定值
        } catch (Exception e) {
            wantouYahuPowerByUnit = 0.;
        }

        CalibrationMachinePipeDto dto = new CalibrationMachinePipeDto(falanYahuPowerByUnit, falanCo2PowerByUnit,falanPowerByUnit, wantouYahuPowerByUnit);

        return dto;
    }

    /**
     * 涂装喷漆-喷漆房分段喷漆
     * @return
     */
    public CalibrationPaintHouseDto calcPaintHouse() {

        List<Double> paintHousePowerByUnitList = new ArrayList<>();     // 喷漆房分段喷漆-单位耗电（KWh/m2）
        List<Double> paintHouseAirByUnitList = new ArrayList<>();       // 喷漆房分段喷漆-单位用压缩空气量(m³/m²)
        List<Double> paintHouseGasByUnitList = new ArrayList<>();       // 喷漆房分段喷漆-单位耗天然气量(m³)

        List<CalibrationPaintHouseEntity> allPaintHouse = calibrationPaintHouseDao.findAll();

        allPaintHouse.forEach(t-> {
            paintHousePowerByUnitList.add(t.getPowerByUnit());
            paintHouseAirByUnitList.add(t.getAirByUnit());
            paintHouseGasByUnitList.add(t.getGasByUnit());
        });

        Double unitAirPower = calcUnitAirPower();

        double paintHousePowerByUnit = 0.;
        try {
            paintHousePowerByUnit = paintHousePowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintHousePowerByUnit = 0.;
        }

        double paintHouseGasByUnit = 0.;
        try {
            paintHouseGasByUnit = paintHouseGasByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintHouseGasByUnit = 0.;
        }

        double paintHouseAirByUnit = 0.;
        try {
            paintHouseAirByUnit = paintHouseAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintHouseAirByUnit = 0.;
        }

        double paintHouseAirPowerByUnit = 0.;
        try {
            paintHouseAirPowerByUnit = paintHouseAirByUnit * unitAirPower;
        } catch (Exception e) {
            paintHouseAirPowerByUnit = 0.;
        }

        CalibrationPaintHouseDto dto = new CalibrationPaintHouseDto(
                unitAirPower,                   // 空气常数
                paintHousePowerByUnit,          // 喷漆房分段喷漆-单位耗电标定值
                paintHouseAirByUnit,            // 喷漆房分段喷漆-单位用压缩空气量标定值
                paintHouseGasByUnit,            // 喷漆房分段喷漆-单位用天然气量标定值
                paintHouseAirPowerByUnit        // 喷漆房分段喷漆-单位耗电能标定值（压缩空气转化）
        );

        return dto;
    }

    /**
     * 涂装喷漆-舱室及船壳喷漆
     * @return
     */
    public CalibrationPaintShipDto calcPaintShip() {

        List<Double> paintShipAirByUnitList = new ArrayList<>();        // 单位用压缩空气量标定值

        List<CalibrationPaintShipEntity> allPaintShip = calibrationPaintShipDao.findAll();

        allPaintShip.forEach(t-> {
            paintShipAirByUnitList.add(t.getAirByUnit());
        });

        Double unitAirPower = calcUnitAirPower();


        double paintShipAirByUnit = 0.;
        try {
            paintShipAirByUnit = paintShipAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintShipAirByUnit = 0.;
        }

        double paintShipAirPowerByUnit = 0.;
        try {
            paintShipAirPowerByUnit = paintShipAirByUnit * unitAirPower;
        } catch (Exception e) {
            paintShipAirPowerByUnit = 0.;
        }

        CalibrationPaintShipDto dto = new CalibrationPaintShipDto(
                unitAirPower,                   // 空气常数
                paintShipAirByUnit,             // 舱室及船壳喷漆-单位用压缩空气量标定值
                paintShipAirPowerByUnit);       // 舱室及船壳喷漆-单位耗电能标定值（压缩空气转化）

        return dto;
    }

    /**
     * 涂装喷漆
     * @return  请使用 calcPaintShip calcPaintHouse
     */
    @Deprecated
    public CalibrationPaintShipHouseDto calcPaintShipHouse() {

        List<Double> paintHousePowerByUnitList = new ArrayList<>();     // 喷漆房分段喷漆-单位耗电（KWh/m2）
        List<Double> paintHouseAirByUnitList = new ArrayList<>();       // 喷漆房分段喷漆-单位用压缩空气量(m³/m²)
        List<Double> paintHouseGasByUnitList = new ArrayList<>();       // 喷漆房分段喷漆-单位耗天然气量(m³)

        List<Double> paintShipAirByUnitList = new ArrayList<>();        // 单位用压缩空气量标定值

        List<CalibrationPaintShipEntity> allPaintShip = calibrationPaintShipDao.findAll();

        List<CalibrationPaintHouseEntity> allPaintHouse = calibrationPaintHouseDao.findAll();

        allPaintShip.forEach(t-> {
            paintShipAirByUnitList.add(t.getAirByUnit());
        });

        allPaintHouse.forEach(t-> {
            paintHousePowerByUnitList.add(t.getPowerByUnit());
            paintHouseAirByUnitList.add(t.getAirByUnit());
            paintHouseGasByUnitList.add(t.getGasByUnit());
        });

        Double unitAirPower = calcUnitAirPower();


        double paintShipAirByUnit = 0.;
        try {
            paintShipAirByUnit = paintShipAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintShipAirByUnit = 0.;
        }

        double paintShipAirPowerByUnit = 0.;
        try {
            paintShipAirPowerByUnit = paintShipAirByUnit * unitAirPower;
        } catch (Exception e) {
            paintShipAirPowerByUnit = 0.;
        }

        double paintHousePowerByUnit = 0.;
        try {
            paintHousePowerByUnit = paintHousePowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintHousePowerByUnit = 0.;
        }

        double paintHouseGasByUnit = 0.;
        try {
            paintHouseGasByUnit = paintHouseGasByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintHouseGasByUnit = 0.;
        }

        double paintHouseAirByUnit = 0.;
        try {
            paintHouseAirByUnit = paintHouseAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            paintHouseAirByUnit = 0.;
        }

        double paintHouseAirPowerByUnit = 0.;
        try {
            paintHouseAirPowerByUnit = paintHouseAirByUnit * unitAirPower;
        } catch (Exception e) {
            paintHouseAirPowerByUnit = 0.;
        }

        CalibrationPaintShipHouseDto dto = new CalibrationPaintShipHouseDto(
                paintHousePowerByUnit,          // 喷漆房分段喷漆-单位耗电标定值
                paintHouseAirByUnit,            // 喷漆房分段喷漆-单位用压缩空气量标定值
                paintHouseGasByUnit,            // 喷漆房分段喷漆-单位用天然气量标定值
                paintHouseAirPowerByUnit,       // 喷漆房分段喷漆-单位耗电能标定值（压缩空气转化）
                paintShipAirByUnit,             // 舱室及船壳喷漆-单位用压缩空气量标定值
                paintShipAirPowerByUnit);       // 舱室及船壳喷漆-单位耗电能标定值（压缩空气转化）

        return dto;
    }

    public CalibrationShipSandDto calcShipSand() {

        List<Double> shipSandAirByUnitList = new ArrayList<>();             // 单位用压缩空气量标定值

        List<CalibrationShipSandEntity> allShipSand = calibrationShipSandDao.findAll();

        allShipSand.forEach(t-> {
            shipSandAirByUnitList.add(t.getAirByUnit());
        });

        Double unitAirPower = calcUnitAirPower();

        double shipSandAirByUnit = 0.;
        try {
            shipSandAirByUnit = shipSandAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            shipSandAirByUnit = 0.;
        }

        double shipSandAirPowerByUnit = 0.;
        try {
            shipSandAirPowerByUnit = unitAirPower * shipSandAirByUnit;
        } catch (Exception e) {
            shipSandAirPowerByUnit = 0.;
        }

        CalibrationShipSandDto dto = new CalibrationShipSandDto(
                unitAirPower,                   // 空气常数
                shipSandAirByUnit,              // 舱室打砂-单位用压缩空气量标定值
                shipSandAirPowerByUnit);        // 舱室打砂-单位耗电能标定值（压缩空气转化）（KWH/m2)

        return dto;
    }


    public CalibrationHouseSandDto calcHouseSand() {

        List<Double> houseSandPowerByUnitList = new ArrayList<>();          // 单位耗电量标定值
        List<Double> houseSandAirByUnitList = new ArrayList<>();            // 单位用压缩空气量标定值

        List<CalibrationHouseSandEntity> allHouseSand = calibrationHouseSandDao.findAll();

        allHouseSand.forEach(t-> {
            houseSandPowerByUnitList.add(t.getPowerByUnit());
            houseSandAirByUnitList.add(t.getAirByUnit());
        });

        double houseSandPowerByUnit = 0.;
        try {
            houseSandPowerByUnit = houseSandPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            houseSandPowerByUnit = 0.;
        }

        double houseSandAirByUnit = 0.;
        try {
            houseSandAirByUnit = houseSandAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            houseSandAirByUnit = 0.;
        }

        CalibrationHouseSandDto dto = new CalibrationHouseSandDto(
                houseSandPowerByUnit,           // 打砂房分段打砂-单位耗电量标定值
                houseSandAirByUnit              // 打砂房分段打砂-单位用压缩空气量标定值
        );

        return dto;
    }

    /**
     * 打砂除锈
     */
    @Deprecated
    public CalibrationHouseShipSandDto calcHouseShipSand() {

        List<Double> houseSandPowerByUnitList = new ArrayList<>();          // 单位耗电量标定值
        List<Double> houseSandAirByUnitList = new ArrayList<>();            // 单位用压缩空气量标定值
        List<Double> shipSandAirByUnitList = new ArrayList<>();             // 单位用压缩空气量标定值

        List<CalibrationHouseSandEntity> allHouseSand = calibrationHouseSandDao.findAll();
        List<CalibrationShipSandEntity> allShipSand = calibrationShipSandDao.findAll();

        allHouseSand.forEach(t-> {
            houseSandPowerByUnitList.add(t.getPowerByUnit());
            houseSandAirByUnitList.add(t.getAirByUnit());
        });

        allShipSand.forEach(t-> {
            shipSandAirByUnitList.add(t.getAirByUnit());
        });

        Double unitAirPower = calcUnitAirPower();

        double houseSandPowerByUnit = 0.;
        try {
            houseSandPowerByUnit = houseSandPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            houseSandPowerByUnit = 0.;
        }

        double houseSandAirByUnit = 0.;
        try {
            houseSandAirByUnit = houseSandAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            houseSandAirByUnit = 0.;
        }

        double shipSandAirByUnit = 0.;
        try {
            shipSandAirByUnit = shipSandAirByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            shipSandAirByUnit = 0.;
        }

        double shipSandAirPowerByUnit = 0.;
        try {
            shipSandAirPowerByUnit = unitAirPower * shipSandAirByUnit;
        } catch (Exception e) {
            shipSandAirPowerByUnit = 0.;
        }

        CalibrationHouseShipSandDto dto = new CalibrationHouseShipSandDto(
                houseSandPowerByUnit,           // 打砂房分段打砂-单位耗电量标定值
                houseSandAirByUnit,             // 打砂房分段打砂-单位用压缩空气量标定值
                shipSandAirByUnit,              // 舱室打砂-单位用压缩空气量标定值
                shipSandAirPowerByUnit);        // 舱室打砂-单位耗电能标定值（压缩空气转化）（KWH/m2)

        return dto;
    }

    /**
     * 超水清洁
     */
    public CalibrationWaterCleanDto calcWaterCleanDto() {

        List<Double> waterPowerByUnitList = new ArrayList<>();               // 超水清洁单位耗电标定值（KWh/m2）

        List<CalibrationWaterCleanEntity> allWater = calibrationWaterCleanDao.findAll();

        allWater.forEach(t-> {
            waterPowerByUnitList.add(t.getPowerUnit());
        });

        double waterPowerByUnit = 0.;
        try {
            waterPowerByUnit = waterPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            waterPowerByUnit = 0.;
        }


        CalibrationWaterCleanDto dto = new CalibrationWaterCleanDto(
                waterPowerByUnit           // 超水清洁单位耗电标定值（KWh/m2）
        );
        return dto;
    }

    /**
     * 超水清洁点打
     * @return
     */
    public CalibrationWaterCleanPointDto calcWaterCleanPointDto() {

        List<Double> waterPointPowerByUnitList = new ArrayList<>();          // 超水清洁点打单位耗电标定值（KWh/m2）

        List<CalibrationWaterCleanPointEntity> allWaterPoint = calibrationWaterCleanPointDao.findAll();

        allWaterPoint.forEach(t-> {
            waterPointPowerByUnitList.add(t.getPowerUnit());
        });

        double waterPointPowerByUnit = 0.;
        try {
            waterPointPowerByUnit = waterPointPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            waterPointPowerByUnit = 0.;
        }

        CalibrationWaterCleanPointDto dto = new CalibrationWaterCleanPointDto(
                waterPointPowerByUnit      // 超水清洁点打单位耗电标定值（KWh/m2）
        );

        return dto;
    }

    public CalibrationWaterCleanRustDto calcWaterRustDto() {

        List<Double> waterRustPowerByUnitList = new ArrayList<>();           // 超水除锈单位耗电标定值（KWh/m2）

        List<CalibrationWaterRustCleanEntity> allWaterRust = calibrationWaterRustCleanDao.findAll();

        allWaterRust.forEach(t-> {
            waterRustPowerByUnitList.add(t.getPowerUnit());
        });

        double waterRustPowerByUnit = 0.;
        try {
            waterRustPowerByUnit = waterRustPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            waterRustPowerByUnit = 0.;
        }

        CalibrationWaterCleanRustDto dto = new CalibrationWaterCleanRustDto(
                waterRustPowerByUnit);      // 超水除锈单位耗电标定值（KWh/m2）

        return dto;
    }

    public CalibrationWaterCleanRustShipDto calcWaterRustShipDto() {

        List<Double> waterRustPowerByUnitList = new ArrayList<>();           // 舱盖超水除锈单位耗电标定值（KWh/m2）

        List<CalibrationWaterCleanRustShipEntity> allWaterRust = calibrationWaterCleanRustShipDao.findAll();

        allWaterRust.forEach(t-> {
            waterRustPowerByUnitList.add(t.getPowerUnit());
        });

        double waterRustPowerByUnit = 0.;
        try {
            waterRustPowerByUnit = waterRustPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            waterRustPowerByUnit = 0.;
        }

        CalibrationWaterCleanRustShipDto dto = new CalibrationWaterCleanRustShipDto(
                waterRustPowerByUnit);      // 超水除锈单位耗电标定值（KWh/m2）

        return dto;
    }


    /**
     * 清洁、超水除锈
     */
    @Deprecated
    public CalibrationWaterDto calcWaterDto() {

        List<Double> waterPointPowerByUnitList = new ArrayList<>();          // 超水清洁点打单位耗电标定值（KWh/m2）
        List<Double> waterPowerByUnitList = new ArrayList<>();               // 超水清洁单位耗电标定值（KWh/m2）
        List<Double> waterRustPowerByUnitList = new ArrayList<>();           // 超水除锈单位耗电标定值（KWh/m2）

        List<CalibrationWaterCleanPointEntity> allWaterPoint = calibrationWaterCleanPointDao.findAll();
        List<CalibrationWaterCleanEntity> allWater = calibrationWaterCleanDao.findAll();
        List<CalibrationWaterRustCleanEntity> allWaterRust = calibrationWaterRustCleanDao.findAll();

        allWaterPoint.forEach(t-> {
            waterPointPowerByUnitList.add(t.getPowerUnit());
        });

        allWater.forEach(t-> {
            waterPowerByUnitList.add(t.getPowerUnit());
        });

        allWaterRust.forEach(t-> {
            waterRustPowerByUnitList.add(t.getPowerUnit());
        });

        double waterPointPowerByUnit = 0.;
        try {
            waterPointPowerByUnit = waterPointPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            waterPointPowerByUnit = 0.;
        }

        double waterPowerByUnit = 0.;
        try {
            waterPowerByUnit = waterPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            waterPowerByUnit = 0.;
        }

        double waterRustPowerByUnit = 0.;
        try {
            waterRustPowerByUnit = waterRustPowerByUnitList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
        } catch (Exception e) {
            waterRustPowerByUnit = 0.;
        }

        CalibrationWaterDto dto = new CalibrationWaterDto(
                waterPointPowerByUnit,      // 超水清洁点打单位耗电标定值（KWh/m2）
                waterPowerByUnit,           // 超水清洁单位耗电标定值（KWh/m2）
                waterRustPowerByUnit);      // 超水除锈单位耗电标定值（KWh/m2）

        return dto;
    }

}
